<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use common\logic\OrderStatus;
use common\logic\SupplyStatus;
use common\logic\PaymentStatus;
use common\logic\AccountStatus;
use common\models\OrderStatusFlow;

/* @var $this yii\web\View */
/* @var $model backend\models\Order */
/* @var $form yii\widgets\ActiveForm */
$trip=\common\models\Trip::getOne("id={$model->trip_id}");
$boat = \common\models\Boat::getOne("id={$trip['boat_id']}");
$bookerTripId = \common\models\Booker::dive2booker($trip['id'],\common\models\Booker::TYPE_TRIP);
?>

<div class="order-form">

    <?php $form = ActiveForm::begin(); ?>

    <?=$form->field($model, 'uid')->textInput([
        'disabled' => 'disabled'
    ])?>

    <?=$form->field($model, 'order_id')->textInput([
        'maxlength' => true,
        'disabled' => 'disabled'
    ])?>
	<div class="form-group">
		<label class="control-label" for="order-ctime">船宿船期</label>
		<p><a href="https://www.cooldive.com.cn/boat/<?=$trip['boat_id']?>/detail">船详情页</a></p>
		<p><a href="https://www.cooldive.com.cn/boat/<?=$trip['boat_id']?>/order?tripId=<?=$model->trip_id?>&cabinId=<?=$model->cabin_id?>">船期下订单页</a></p>
		<p><a href="<?=$boat['booker_url']?>">对应 Booker详情页</a></p>
		<p><a href="https://divebooker.com/boatorder/booking/?tripId=<?=$bookerTripId?>">对应 Booker船期页</a></p>
	</div>

	<div class="form-group">
		<label class="control-label" for="order-utime">当前状态</label>
		<table class="table table-bordered">
			<thead>
			<tr>
				<th>订单状态</th>
				<th>供应商状态</th>
				<th>支付状态</th>
				<th>结算状态</th>
			</tr>
			</thead>
			<tbody>
				<tr class="active">
					<td><?=OrderStatus::TEXT[$model->order_status]?></td>
					<td><?=SupplyStatus::TEXT[$model->supply_status]?></td>
					<td><?=PaymentStatus::TEXT[$model->payment_status]?></td>
					<td><?=AccountStatus::TEXT[$model->account_status]?></td>
				</tr>
			</tbody>
		</table>
	</div>
	<div class="form-group">
		<label class="control-label" for="order-utime">状态变化</label>
		<table class="table table-bordered">
			<thead>
			<tr>
				<th>序号</th>
				<th>说明</th>
				<th><?=OrderStatusFlow::STATUS_TEXT[OrderStatusFlow::TYPE_ORDER]?></th>
				<th><?=OrderStatusFlow::STATUS_TEXT[OrderStatusFlow::TYPE_SUPPLY]?></th>
				<th><?=OrderStatusFlow::STATUS_TEXT[OrderStatusFlow::TYPE_PAYMENT]?></th>
				<th><?=OrderStatusFlow::STATUS_TEXT[OrderStatusFlow::TYPE_ACCOUNT]?></th>
				<th>发生时间</th>
			</tr>
			</thead>
			<tbody>
            <?php foreach ($flow as $k=>$item) { ?>
				<tr>
					<td><?=$k+1?></td>
					<td><?=$item['reason']??''?></td>
					<td><?=isset($item[OrderStatusFlow::TYPE_ORDER]) ? OrderStatus::TEXT[$item[OrderStatusFlow::TYPE_ORDER]] : ''?></td>
					<td><?=isset($item[OrderStatusFlow::TYPE_SUPPLY]) ? SupplyStatus::TEXT[$item[OrderStatusFlow::TYPE_SUPPLY]] : ''?></td>
					<td><?=isset($item[OrderStatusFlow::TYPE_PAYMENT]) ? PaymentStatus::TEXT[$item[OrderStatusFlow::TYPE_PAYMENT]] : ''?></td>
					<td><?=isset($item[OrderStatusFlow::TYPE_ACCOUNT]) ? AccountStatus::TEXT[$item[OrderStatusFlow::TYPE_ACCOUNT]] : ''?></td>
					<td><?=date('Y/m/d H:i:s',$item['ctime']/1000)?></td>
				</tr>
            <?php }?>
			</tbody>
		</table>
	</div>

    <?=$form->field($model, 'deleted')->textInput([
        'disabled' => 'disabled',
        'value' => $model->deleted ? '是' : '否'
    ])?>

    <?=$form->field($model, 'trip_id')->textInput(['disabled'=>''])?>

    <?=$form->field($model, 'cabin_id')->textInput()?>
    <?=$form->field($model, 'one_self')->dropDownList([
        \common\models\Order::ONE_SELF => '是',
        \common\models\Order::NOT_ONE_SELF => '否',
    ])?>
    <?=''//$form->field($model, 'occupancy_id')->dropDownList([0=>1,1=>'b'])?>
    <?=$form->field($model, 'price')->textInput([
        'disabled' => 'disabled',
        'value' => '￥'.$model->price / 100
    ])?>
    <?=$form->field($model, 'unitprice')->textInput([
        'disabled' => 'disabled',
        'value' => '€'.$model->unitprice / 100
    ])?>
    <?=$form->field($model, 'exchange_rate')->textInput(['disabled' => 'disabled',])?>
    <?='';//$form->field($model, 'contact')->textInput(['maxlength' => true])?>
	<div class="form-group">
		<label class="control-label" for="order-utime">预订人</label>
		<table class="table">
            <?php $contact = json_decode($model->contact, true);
            foreach ($contact as $item) { ?>
				<tr>
					<td>姓名：<?=$item['name']?></td>
					<td>性别：<?=\common\models\User::GENDER_TEXT[$item['gender']]?></td>
					<td>Email：<?=$item['email']?></td>
				</tr>
			<?php }?>
		</table>
	</div>
    <?=$form->field($model, 'first_name')->textInput()?>
    <?=$form->field($model, 'last_name')->textInput()?>


    <?=$form->field($model, 'payment')->textarea(['rows' => 6])?>
    <?=$form->field($model, 'ext')->textarea(['rows' => 6])?>

    <?=$form->field($model, 'email')->textInput(['maxlength' => true])?>

    <?=$form->field($model, 'phone')->textInput(['maxlength' => true])?>

    <?=$form->field($model, 'fund_amount')->textInput(['disabled'=>''])?>
    <?=$form->field($model, 'use_protect')->textInput(['maxlength' => true])?>

    <?=$form->field($model, 'message')->textInput(['maxlength' => true])?>

	<div class="form-group">
        <?=Html::submitButton('保存', ['class' => 'btn btn-success'])?>
        <?=Html::a('取消', Yii::$app->user->getReturnUrl(),['class' => 'btn btn-default'])?>
	</div>

    <?php ActiveForm::end(); ?>

</div>
